/*
 * OccurrenceTests.cpp
 *
 *  Created on: Mar 2, 2011
 *      Author: Craig Wilson
 */

#include "../src/Occurrence.cpp"
#include "../src/OccurrenceSet.cpp"
#include "../src/KeyWordIndex.cpp"
//#include "../inc/URL.h"
#include <string>

	extern URL array[];
	extern string d1,d2,d3,d4;
	extern LinkedList<URL> l1,l2,l3;
	extern Page *p1,*p2,*p3;
	extern Occurrence *o1,*o2,*o3,*o4;
	extern OccurrenceSet *oSet1,*oSet2;
	extern KeyWordIndex *Index;

	extern void iniValues();

	int OccurrenceTests(){
		iniValues();
		o2->increment();
		o2->increment();
		o2->increment();
		o3->increment();
		o3->increment();
		if (o1->getCount()!=0 || o2->getCount()!=3 || o3->getCount()!=2)
			return 1; //Increment or get count wrong
		if (o1->getSite()->compare(*p1)!=0 || o2->getSite()->compare(*p3)==0 ||o3->getSite()->compare(*p3)!=0 )
			return 2; //URL Issue
		delete o1;
		if(p1->compare(*p2)==0)
			return 3; //Mostly checking that page wansn't deleted

		return 0;
	}

	int OccurrenceSetTests(){
			iniValues();

			oSet1->add(*p1);
			oSet1->add(*p1);
			oSet1->add(*p1);
			oSet1->add(*p2);
			oSet1->add(*p1);
			oSet2->add(*p1);
			oSet2->add(*p2);
			oSet2->add(*p2);
			oSet2->add(*p3);
			oSet2->add(*p3);
			oSet2->add(*p3);
			oSet2->add(*p3);

			if (oSet1->contains(*p1)!=true || oSet1->contains(*p3)==true || oSet2->contains(*p3)==false)
				return 1; //Adding or contains method wrong

			Occurrence *otemp1=oSet1->get(*p1);
			Occurrence *otemp2=oSet1->get(*p2);
			Occurrence *otemp3=oSet1->get(*p3);
			Occurrence *otemp4=oSet2->get(*p1);
			Occurrence *otemp5=oSet2->get(*p2);
			Occurrence *otemp6=oSet2->get(*p3);
			if (otemp3!=NULL)
				return 2; //get is wrong
			if (otemp1->getCount()!=4 ||otemp2->getCount()!=1 ||otemp4->getCount()!=1 ||otemp5->getCount()!=2 ||otemp6->getCount()!=4)
				return 3; //Count not incrementing correctly
			return 0;
		}

	int KeyWordIndexTests(){
		iniValues();
		string words[4]= {"hello", "test","avacado","horse"};
		Index->add(words[0],*p1);
		Index->add(words[0],*p1);
		Index->add(words[1],*p1);
		Index->add(words[2],*p1);
		Index->add(words[2],*p1);
		Index->add(words[2],*p1);
		Index->add(words[1],*p2);
		Index->add(words[1],*p2);
		Index->add(words[0],*p2);
		Index->add(words[0],*p2);
		Index->add(words[3],*p3);
		Index->add(words[3],*p3);
		Index->add(words[3],*p3);
		Index->add(words[3],*p3);

		return 0;
	}
